package cn.zqy.demo3.day01.Jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo05JdbcCreateTab {
    public static void main(String[] args) {
        Connection conn = null;
        Statement statement = null;
        try {
            //1. 注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2.获取连接对象
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/heima",
                    "root", "123456");
            //3.获取执行sql对象
            statement = conn.createStatement();
            //4.定义sql
            String sql = "CREATE table  jdbcss(id int primary key , name varchar (20))";
            //5.执行sql
            int num = statement.executeUpdate(sql);
            //6.处理结果
            System.out.println(num);
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        } finally {
            //7.释放资源
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
